/*
 * @Description:
 * @Author: Zzt
 * @Date: 2022-11-10 16:49:18
 * @LastEditTime: 2023-01-05 17:45:03
 */
import { createContext, useReducer, useEffect, useContext } from 'react';
import { SET_CHART_DATA, SET_TABLE_DATA } from '../constants';
import { systemForTable, systemForStat } from '@/api/statistics/statistics';
import { UserPermissionsReducer } from '../reducers/UserPermissionsReducer';
const initialState = {
  dataList: [],
  chartList: []
};
const UserPermissionsContext = createContext();
const UserPermissionsContextProvider = (props) => {
  const [state, dispatch] = useReducer(UserPermissionsReducer, initialState);
  const actions = {
    setChartData(data) {
      systemForStat({ ...data, menuType: 2 }).then((res) => {
        const { data } = res;
        dispatch({ type: SET_CHART_DATA, data });
      });
    },
    setTableData(data) {
      systemForTable({ ...data }).then((res) => {
        const { data } = res;
        console.log('datadata', data);
        dispatch({ type: SET_TABLE_DATA, data });
      });
    }
  };
  useEffect(() => {}, []);
  return (
    <UserPermissionsContext.Provider value={{ ...state, ...actions }}>
      {props.children}
    </UserPermissionsContext.Provider>
  );
};
export const useUserPermissionsContext = () => {
  return useContext(UserPermissionsContext);
};
export { UserPermissionsContext, UserPermissionsContextProvider };
